const timeUtil = {
  getDate(unixTime) {
    console.log(unixTime)
    if (!unixTime) {
      return ''
    }
    if(navigator.appVersion.match(/iPhone/ig)) {
      unixTime = unixTime.split('.')[0];
    }
    const date = new Date(unixTime)
    return `${date.getFullYear().toString().substring(2)}/${date.getMonth() + 1}/${date.getDate()}`
  },
  getTime(unixTime) {
    if (!unixTime) {
      return ''
    }
    if(navigator.appVersion.match(/iPhone/ig)) {
      unixTime = unixTime.split('.')[0];
    }
    const date = new Date(unixTime)
    const hours = date.getHours()
    const formatedHours = hours >= 10 ? hours : '0' + hours
    const minutes = date.getMinutes()
    const formatedMinutes = minutes >= 10 ? minutes : '0' + minutes
    const seconds = date.getSeconds()
    const formatedSeconds = seconds >= 10 ? seconds : '0' + seconds
    return `${formatedHours}:${formatedMinutes}:${formatedSeconds}`
  },
  dataURLtoBlob(dataurl) {
    var arr = dataurl.split(',')
    var mime = arr[0].match(/:(.*?);/)[1]
    var bstr = atob(arr[1])
    var n = bstr.length
    var u8arr = new Uint8Array(n);
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: mime });
  },
  blobToDataURL(blob, callback) {
    var a = new FileReader()
    a.onload = function (e) { callback(e.target.result) }
    a.readAsDataURL(blob)
  }
}

export default timeUtil